<@sys.site id=siteId><#assign a=object/></@sys.site>
<@tools.disk>
<#assign
    realRootPath=rootPath?replace('\\','/')
    dynamicPath=a.dynamicPath?keep_after('//')?keep_before('/')?keep_before(':')
    dynamicLocation=a.dynamicPath?keep_after('//')?keep_after('/')
    dynamicPort=a.dynamicPath?keep_after('//')?keep_before('/')?keep_after(':')
    sitePath=a.sitePath?keep_after('//')?keep_before('/')?keep_before(':')
    siteLocation=a.sitePath?keep_after('//')?keep_after('/')
    sitePort=a.sitePath?keep_after('//')?keep_before('/')?keep_after(':')
/>
</@tools.disk>
<div class="pageFormContent" layoutH>
    <dl class="nowrap">
        <dt><@t.page 'site'/>:</dt>
        <dd>
            ${(a.name)!}
            <span class="info"><@t.page 'server_config.nginx_description'/></span>
        </dd>
    </dl>
    <dl class="nowrap">
        <dt><@t.page 'server_config.nginx'/>:</dt>
        <dd>
            <textarea class="code" mode="nginx">
#<@t.page 'server_config.nginx_common_description'/>
upstream cms {
    #<@t.page 'server_config.upstream'/>
    ip_hash;
    server localhost:8080  weight=1;
}

<@sys.domainList advanced=true siteId=siteId>
#${a.name} <@t.page 'server_config.site'/>
server {
    listen       ${dynamicPort?has_content?then(dynamicPort,80)};
    #listen 443 ssl;
    server_name  ${dynamicPath} <#list page.list as d><#if d.name!=dynamicPath>${d.name}</#if><#if d.wild> *.${d.name}</#if><#if d.multiple><#assign multipleDomain=d/></#if><#sep> </#list>;
    
    #ssl_certificate cert/xxx.pem;
    #ssl_certificate_key cert/xxx.key;
     
        <#if a.useSsi>
    ssi on;
    ssi_silent_errors on;
        </#if>
    location <#if dynamicPath=sitePath&&dynamicPort=sitePort&&dynamicLocation=siteLocation>@cmsproxy<#else>${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}</#if> {
        client_max_body_size 100m;
        proxy_redirect off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_connect_timeout 5;
        proxy_send_timeout 30;
        proxy_read_timeout 10;
        proxy_pass http://cms;
    }

        <#if a.useSsi>
    location /include/ {
        alias ${realRootPath}/web/site_${siteId}/include/;
    }
        </#if>
        <#if dynamicPath=sitePath&&dynamicPort=sitePort>
    #${a.name} <@t.page 'server_config.static'/>
    location ${siteLocation?has_content?then('/'+siteLocation,'/')} {
        alias   ${realRootPath}/web/site_${siteId}/;
        index   index.html;
        <#if dynamicLocation=siteLocation>
        try_files  $uri  $uri/  @cmsproxy; 
        </#if>
    }
            <#if multipleDomain?has_content>
                <@sys.siteList parentId=multipleDomain.siteId pageSize=100>
                    <#list page.list as a>
                        <#if a.directory?has_content>
    #${a.name} <@t.page 'server_config.static'/>
    location ${siteLocation?has_content?then('/'+siteLocation,'/')}${a.directory}/ {
        alias   ${realRootPath}/web/site_${a.id}/;
        index  index.html;
        <#if dynamicLocation=siteLocation>
        try_files  $uri  $uri/  @cmsproxy; 
        </#if>
    }
                        </#if>
                    </#list>
                </@sys.siteList>
            </#if>
        <#else>
    location ${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}webfile/ {
        alias   ${realRootPath}/web/site_${siteId}/webfile/;
        index  index.html;
    }
    
            <#if multipleDomain?has_content>
                <@sys.siteList parentId=multipleDomain.siteId pageSize=100>
                    <#list page.list as a>
                        <#if a.directory?has_content>
    location ${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}webfile/${a.directory}/ {
        alias   ${realRootPath}/web/site_${a.id}/webfile/;
        index  index.html;
    }
                        </#if>
                    </#list>
                </@sys.siteList>
            </#if>
        </#if>
    error_page 403 /error/403.html;
    error_page 404 /error/403.html;
    error_page 500 502 503 504 /error/500.html;
}
</@sys.domainList>
<#if dynamicPath!=sitePath||dynamicPort!=sitePort>
#${a.name} <@t.page 'server_config.static'/>
server {
    listen       ${sitePort?has_content?then(sitePort,80)}; #<@t.page 'server_config.port'/>
    server_name  ${sitePath};
    <#if a.useSsi>
    ssi on;
    ssi_silent_errors on;
    ssi_types text/shtml;

        <#if siteLocation?has_content>
    location /include/ {
        alias ${realRootPath}/web/site_${siteId}/include/;
    }
        </#if>
    </#if>

    location ${siteLocation?has_content?then('/'+siteLocation,'/')} {
        alias   ${realRootPath}/web/site_${siteId}/;
        index  index.html;
        add_header Access-Control-Allow-Origin *;
    }
    
    <#if multipleDomain?has_content>
        <@sys.siteList parentId=multipleDomain.siteId pageSize=100>
            <#list page.list as a>
                <#if a.directory?has_content>
    location ${siteLocation?has_content?then('/'+siteLocation,'/')}${a.directory}/ {
        alias   ${realRootPath}/web/site_${a.id}/;
        index  index.html;
    }
                </#if>
            </#list>
        </@sys.siteList>
    </#if>
    error_page 403 /error/403.html;
    error_page 404 /error/403.html;
    error_page 500 502 503 504 /error/500.html;
}
</#if></textarea>
            <span class="info"><@t.page 'server_config.nginx_config_description'/></span>
        </dd>
    </dl>
    <dl class="nowrap">
        <dt><@t.page 'server_config.apache'/>:</dt>
        <dd>
            <textarea class="code" mode="xml">
#<@t.page 'server_config.apache_common_description'/>
ProxyRequests off
ProxyPreserveHost On
<Proxy "balancer://cmsproxy">
    BalancerMember "http://localhost:8080" loadfactor=1
    ProxySet stickysession=JSESSIONID
</Proxy>

#${a.name} <@t.page 'server_config.site'/>
<Directory "${realRootPath}/web/site_${siteId}/">
    AllowOverride None
    Options Indexes FollowSymLinks Includes
    Require all granted
</Directory>

<VirtualHost *:${dynamicPort?has_content?then(dynamicPort,80)}>
    ServerName ${dynamicPath}
<@sys.domainList advanced=true siteId=siteId>
  <#if page.totalCount gt 0>
    ServerAlias <#list page.list as d><#if d.name!=dynamicPath&&d.name!=sitePath>${d.name}</#if><#if d.wild> *.${d.name}</#if><#sep> </#list>
  </#if>
</@sys.domainList>
  <#if a.useSsi>
    alias /include/ "${realRootPath}/web/site_${siteId}/include/"
    AddType text/html .html .shtml
    AddOutputFilter INCLUDES .html .shtml
  </#if>
    ProxyPass ${dynamicLocation?has_content?then('/'+dynamicLocation,'/')} balancer://cmsproxy${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}
    ProxyPassReverse ${dynamicLocation?has_content?then('/'+dynamicLocation,'/')} balancer://cmsproxy${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}
    
    <#if multipleDomain?has_content>
        <@sys.siteList parentId=multipleDomain.siteId pageSize=100>
            <#list page.list as a>
                <#if a.directory?has_content>
    Alias ${siteLocation?has_content?then('/'+siteLocation,'/')}${a.directory}/ "${realRootPath}/web/site_${a.id}/webfile/"
                    <#if dynamicLocation=siteLocation>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://cmsproxy/%{REQUEST_URI} [P,L]
                    </#if>
                </#if>
            </#list>
        </@sys.siteList>
    </#if>
    <#if dynamicPath=sitePath&&dynamicPort=sitePort>
    #${a.name} <@t.page 'server_config.static'/>
    Alias "/${siteLocation}" "${realRootPath}/web/site_${siteId}/"
         <#if dynamicLocation=siteLocation>
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT} %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT} %{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://cmsproxy/%{REQUEST_URI} [P,L]
        </#if>
    <#else>
    Alias "${dynamicLocation?has_content?then('/'+dynamicLocation,'/')}webfile/" "${realRootPath}/web/site_${siteId}/webfile/"
    </#if>
    ErrorDocument 403 /error/403.html
    ErrorDocument 404 /error/403.html
    ErrorDocument 500 /error/500.html
    ErrorDocument 502 /error/500.html
    ErrorDocument 503 /error/500.html
    ErrorDocument 504 /error/500.html
</VirtualHost>

<#if dynamicPath!=sitePath||dynamicPort!=sitePort>
#${a.name} <@t.page 'server_config.static'/>
<VirtualHost *:${sitePort?has_content?then(sitePort,80)}>
    ServerName ${sitePath}
    <#if a.useSsi>
        <#if siteLocation?has_content>
    alias /include/ "${realRootPath}/web/site_${siteId}/include/"
    AddType text/html .html .shtml
    AddOutputFilter INCLUDES .html .shtml
        </#if>
    </#if>
    <#if multipleDomain?has_content>
        <@sys.siteList parentId=multipleDomain.siteId pageSize=100>
            <#list page.list as a>
                <#if a.directory?has_content>
    #${a.name} <@t.page 'server_config.static'/>
    alias ${siteLocation?has_content?then('/'+siteLocation,'/')}${a.directory}/ "${realRootPath}/web/site_${a.id}/"
                </#if>
            </#list>
        </@sys.siteList>
    </#if>
    <#if siteLocation?has_content>
    Alias "/${siteLocation}/" "${realRootPath}/web/site_${siteId}/"
    <#else>
    DocumentRoot "${realRootPath}/web/site_${siteId}/" 
    </#if>
    <IfModule headers_module>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
    ErrorDocument 403 /error/403.html
    ErrorDocument 404 /error/403.html
    ErrorDocument 500 /error/500.html
    ErrorDocument 502 /error/500.html
    ErrorDocument 503 /error/500.html
    ErrorDocument 504 /error/500.html
</VirtualHost>
</#if>
</textarea>
        </dd>
    </dl>
    <dl class="nowrap">
        <dt><@t.page 'server_config.tomcat'/>:</dt>
        <dd><textarea class="code" mode="xml">
&lt;!-- this valve replaces the apparent client remote IP address and hostname and scheme for the request --&gt;
&lt;Valve className="org.apache.catalina.valves.RemoteIpValve" protocolHeader="X-Forwarded-Proto"/&gt;</textarea>
            <span class="info"><@t.page 'server_config.tomcat_description'/></span>
        </dd>
    </dl>
</div>
<div class="formBar card">
    <ul>
        <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
    </ul>
</div>